package org.genntii.smcommentlike.controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.genntii.smcommentlike.service.CommentLikeService;
import org.genntii.smcommon.result.Result;
import org.genntii.smdomain.dto.CommentLIkeDTO;
import org.genntii.smdomain.vo.LikeVO;
import org.springframework.web.bind.annotation.*;

@Tag(name = "评论点踩")
@RestController
@RequestMapping("/comment_like")
public class CommentLikeController {

    @Resource
    private CommentLikeService commentLikeService;

    /**
     * 直接请求
     */
    @Operation(summary = "取消点赞")
    @DeleteMapping
    public Result delCommentLike(@RequestParam("commentId") Long commentId, HttpServletRequest request){
        Long userId = Long.valueOf(request.getHeader("user-id"));
        commentLikeService.delCommentLIke(commentId, userId);
        return Result.success();
    }

    /**
     * 直接请求
     */
    @Operation(summary = "点赞/踩")
    @PostMapping
    public Result likeComment(@RequestBody CommentLIkeDTO dto,HttpServletRequest request){
        Long userId = Long.valueOf(request.getHeader("user-id"));
        commentLikeService.commentLike(userId, dto.getCommentId(),dto.getLike());
        return Result.success();
    }

    /**,
     * client获取
     */
    @Operation(summary = "获得点赞情况")
    @GetMapping
    public Result<LikeVO> getCommentLIkeVO(@RequestParam("commentId") Long commentId, @RequestParam("userId") Long userId){
        return Result.success(commentLikeService.getCommentLikeVO(commentId,userId));
    }


}
